﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MINERP.Statistics.ShopBill
{
    public partial class FrmShopBillNoPay : Form
    {
        private BLL.Statistics.StatisticsBLL SSBLL = new MINERP.BLL.Statistics.StatisticsBLL();

        public FrmShopBillNoPay()
        {
            InitializeComponent();
        }

        #region 单件
        //单件
        private static FrmShopBillNoPay _instance;
        public static FrmShopBillNoPay Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new FrmShopBillNoPay();
                }
                else if (_instance.IsDisposed)
                {
                    _instance = new FrmShopBillNoPay();
                }
                return _instance;
            }
        }
        #endregion

        #region Load
        private void FrmShopBillNoPay_Load(object sender, EventArgs e)
        {
            DateTime now = DateTime.Now;
            string nowStr = now.ToString("yyyy-MM-dd HH:mm");
            dtStartTime.Text = nowStr;
            dtEndTime.Text = nowStr;
        }
        #endregion

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime startTime = dtStartTime.DateTime;
                DateTime endTime = dtEndTime.DateTime;
                if (startTime >= endTime)
                    return;
                DataTable shopNoPay = SSBLL.GetShopBillNoPay(startTime, endTime);
                shopNoPay.TableName = "tableShopNoPay";
                DataTable TimeDT = SSBLL.GetTimeDT(startTime, endTime);
                TimeDT.TableName = "tableStartAndEndTime";
                DataSet set = new DataSet();
                set.Tables.Add(shopNoPay);
                set.Tables.Add(TimeDT);

                set.WriteXml(@"C:\Windows\xmldata\ShopBillNoPay.xml", XmlWriteMode.WriteSchema);
                report.Preview = previewControl1;
                report.RegisterData(set);
                report.Load(Application.StartupPath + "\\frxShopBillNoPay.frx");
                previewControl1.Refresh();
                previewControl1.Show();
                report.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "确认", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void FrmShopBillNoPay_FormClosing(object sender, FormClosingEventArgs e)
        {
            _instance.Dispose();
            _instance = null;
        }

       
    }
}
